#include "../../../include/offline/DirScanner.hpp"

using std::vector;
using std::string;
using std::cout;
using std::endl;


void DirScanner::getFiles(const string& path) {
    DIR *dir;
    struct dirent *ptr;
    if ((dir = opendir(path.c_str())) == NULL) {
        perror("Open dir error");
        return;
    }

    while ((ptr = readdir(dir)) != NULL) {
        if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0) {
            continue;
        } else if (ptr->d_type == 8) {// file
            string strFile;
            strFile = path;
            strFile += "/";
            strFile += ptr->d_name;
            _files.push_back(strFile);
        }
        else {
            continue;
        }
    }
    closedir(dir);
}

vector<string> DirScanner::files() {
    return _files;
}

/*test code*/
// int main() {
//     string path = "../../../data/corpus/module2";
//     vector<string> files;
//     DirScanner scanner;
//     scanner.getFiles(path, files);

//     for (auto &e:files) {
//         cout << e << endl;
//     }

//     return 0;
// }